<template>
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="48">
          <a-col :md="6" :sm="24">
            <a-form-item label="模块标识">
              <a-input v-model="queryParam.dto.type" placeholder="" />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-form-item label="操作账户">
              <a-input v-model="queryParam.dto.userAccount" placeholder="" />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-form-item label="IP地址">
              <a-input v-model="queryParam.dto.ip" placeholder="" />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <span
              class="table-page-search-submitButtons"
              :style="advanced && { float: 'right', overflow: 'hidden' } || {} ">
              <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
              <a-button style="margin-left: 8px" @click="resetSearchForm()">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <div class="table-operator">
    </div>
    <s-table
      ref="table"
      size="small"
      bordered
      rowKey="id"
      :columns="columns"
      :data="loadData">
      <span slot="params" slot-scope="text">
        <span v-html="$substr(text,10)"></span>
      </span>

      <span slot="method" slot-scope="text">
        <span v-html="$substr(text,10)"></span>
      </span>

    </s-table>

  </a-card>
</template>

<script>
  import moment from 'moment'
  import {
    page
  } from '@/api/system/log'
  import {
    STable
  } from '@/components'
  export default {
    name: 'TableList',
    components: {
      STable
    },
    props: {
      statusFilter: {
        type: Function,
        default: undefined
      }
    },
    data () {
      return {
        mdl: {},
        advanced: false,
        queryParam: {
          dto: {}
        },
        columns: [{
            title: '模块标识',
            dataIndex: 'type'
          },
          {
            title: '模块名称',
            dataIndex: 'module'
          },
          {
            title: '操作账户',
            dataIndex: 'userAccount'
          },
          {
            title: '用户操作',
            dataIndex: 'operation'
          },
          {
            title: '响应时间',
            dataIndex: 'time',
            customRender: (text) => {
              if (text < 1000) {
                return text + '  ms'
              } else if (text >= 1000) {
                return (text / 1000) + '  s'
              } else {
                return text + '  ms'
              }
            }
          },
          {
            title: '请求方法',
            dataIndex: 'method',
            scopedSlots: {
              customRender: 'method'
            }
          },
          {
            title: '请求参数',
            dataIndex: 'params',
            scopedSlots: {
              customRender: 'params'
            }
          },
          {
            title: 'IP地址',
            dataIndex: 'ip'
          },
          {
            title: '创建时间',
            dataIndex: 'gmtCreate',
            sorter: true,
            needTotal: false,
            customRender: (text) => {
              if (text) {
                return moment(text).format('YYYY-MM-DD HH:mm:ss')
              }
            }
          }
        ],
        loadData: parameter => {
          return page(Object.assign(parameter, this.queryParam)).then(response => {
            return response.res
          })
        }
      }
    },
    created () {},
    methods: {
      handleEdit (record) {
        this.$refs.formHandle.edit(record)
      },
      handleOk () {
        this.$refs.table.refresh()
      },
      resetSearchForm () {
        this.queryParam = {
          dto: {}
        }
        this.handleOk()
      }
    }
  }
</script>
